// 路由配置
import {createRouter, createWebHistory} from "vue-router";

// 路由配置规则
const routes = [
    {path: "/", redirect: "/home"},
    //主页路由
    {
        path: "/home",
        name: "home",
        meta: {title: "就业职通车"},
        // @ts-ignore
        component: () => import("@/pages/home.vue"),
    }, //使用时进行加载
    //招聘页路由
    {
        path: "/job",
        name: "job",
        meta: {title: "招聘岗位"},
        // @ts-ignore
        component: () => import("@/pages/jobs.vue"),
    },
    //简历页路由
    {
        path: "/vitae",
        name: "vitae",
        meta: {title: "简历管理"},
        // @ts-ignore
        component: () => import("@/pages/vitae.vue"),
    },
    //“我的”页路由
    {
        path: "/mine",
        name: "mine",
        meta: {title: "我的"},
        // @ts-ignore
        component: () => import("@/pages/mine.vue"),
    },
    //   招聘详情
    {
        path: "/jobDetail/:id",
        name: "jobDetail",
        meta: {title: "招聘详情"},
        // @ts-ignore
        component: () => import("@/pages/jobDetail.vue"),
    },
    // 登录页
    {
        path: '/login',
        name: "login",
        meta: {title: "注册登录"},
        component: () => import('@/pages/login.vue')
    },
    //投递页
    {
        path: '/recode',
        name: "recode",
        meta: {title: "投递记录"},
        component: () => import('@/pages/recode.vue')
    },
    // 简历页
    {
        path: '/addvitae/:id?',
        name: "addvitae",
        meta: {title: "简历管理"},
        component: () => import('@/pages/addVitae.vue')
    },
    //404页面
    {
        path: "/404",
        name:  "404",
        meta: {title: "未找到该页面"},
        component: () => import("@/pages/404.vue"),

    },
    // 重定向
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404'
    }
];


// 创建路由实例
const router = createRouter({
    history: createWebHistory(), //使用模式
    routes: routes, // 导入路由配置规则
    linkActiveClass: "active", // 设置激活的样式类名
});
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        // @ts-ignore
        document.title = to.meta.title; //修改网页的标题
    }
    return next();
});
export default router; //导出
